/**
 * 网络请求配置
 */
import axios from "axios";

axios.defaults.timeout = 100000;
// axios.defaults.baseURL = "https://api.uomg.com/";
axios.defaults.baseURL = "/api";

/**
 * http request 拦截器
 */
axios.interceptors.request.use(
    (config) => {
        // config.data = JSON.stringify(config.data);
        config.headers = {
            "Content-Type": "application/json",
        };
        return config;
    },
    (error) => {
        return Promise.reject(error);
    }
);

/**
 * http response 拦截器
 */
axios.interceptors.response.use(
    (response) => {
        if (response.data.errCode === 2) {
            console.log("过期");
        }
        return response;
    },
    (error) => {
        console.log("请求出错：", error);
    }
);

export default axios;


//失败提示
function msag(err) {
    if (err && err.response) {
        switch (err.response.status) {
            case 400:
                alert(err.response.data.error.details);
                break;
            case 401:
                alert("未授权，请登录");
                break;
            case 403:
                alert("拒绝访问");
                break;
            case 404:
                alert("请求地址出错");
                break;
            case 408:
                alert("请求超时");
                break;

            case 500:
                alert("服务器内部错误");
                break;
            case 501:
                alert("服务未实现");
                break;
            case 502:
                alert("网关错误");
                break;
            case 503:
                alert("服务不可用");
                break;
            case 504:
                alert("网关超时");
                break;
            case 505:
                alert("HTTP版本不受支持");
                break;
            default:
        }
    }
}
